//
//  XSAlbumListViewController.m
//  AudioVideo
//
//  Created by xueshan1 on 2019/9/16.
//  Copyright © 2019 xueshan1. All rights reserved.
//

#import "XSAlbumListViewController.h"
#import "XSAlbumListTableViewCell.h"

@interface XSAlbumListViewController ()

@property(nonatomic,strong)NSMutableArray *dataArray;

@end

@implementation XSAlbumListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.tableView registerNib:[UINib nibWithNibName:@"XSAlbumListTableViewCell" bundle:nil] forCellReuseIdentifier:@"cellID"];
    [self initData];
}
- (void)setupUI{
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithColor:[UIColor whiteColor] highColor:[UIColor lightGrayColor] target:self action:@selector(cancleBtnClick) title:@"取消"];

}
- (void)initData{
    [XSPhotosManager getAlbumList:self.selectVideo allowSelectImage:!self.selectVideo complete:^(NSArray<XSAlbumListModel *> *albumList) {
        [self.dataArray addObjectsFromArray:albumList];
        [self.tableView reloadData];
        
    }];
    
}

- (void)cancleBtnClick{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    
}

- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray arrayWithCapacity:5];
    }
    return _dataArray;
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
     return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    XSAlbumListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID" forIndexPath:indexPath];
     
    cell.model = self.dataArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    XSThumbnailViewController *thumbVC = [XSThumbnailViewController new];
    thumbVC.maxSelectCount = 1;
    thumbVC.albumListModel = self.dataArray[indexPath.row];
    [self.navigationController pushViewController:thumbVC animated:YES];
}

@end
